package de.breitbeil.jbooking.ui.view;

import de.breitbeil.jbooking.domain.Event;
import de.breitbeil.jbooking.ui.dataview.DataView;
import de.breitbeil.jbooking.ui.dataview.columns.DataViewColumnImpl;
import de.breitbeil.jbooking.ui.dataview.columns.PropertyDataViewColumn;
import de.breitbeil.jbooking.ui.dataview.columns.StringPropertyDataViewColumn;
import de.breitbeil.jbooking.ui.form.EventForm;
import de.breitbeil.jbooking.ui.view.tablecellrenderer.BookingFromToTableCellRenderer;
import de.breitbeil.jbooking.ui.view.tablecellrenderer.PersonTableCellRenderer;
import de.breitbeil.jbooking.util.BookingFromComparator;

public class EventView extends DataView {

    public EventView() throws InstantiationException, IllegalAccessException {
        super("eventView", Event.class, EventForm.class);
    }

    @Override
    public void init() {
        addColumn(new PropertyDataViewColumn("deadline"));
        addColumn(new StringPropertyDataViewColumn("comment"));
        addColumn(new PropertyDataViewColumn("done"));
        addColumn(createPersonColumn());
        addColumn(createBookingColumn());
    }

    protected DataViewColumnImpl createPersonColumn() {
        PersonTableCellRenderer renderer = new PersonTableCellRenderer();
        DataViewColumnImpl column = new DataViewColumnImpl("person");
        column.setFilterProperties(new String[]{"person.lastname", "person.firstname"});
        column.setCellRenderer(renderer);
        column.setComparator(renderer);
        return column;
    }

    protected DataViewColumnImpl createBookingColumn() {
        BookingFromToTableCellRenderer renderer = new BookingFromToTableCellRenderer();
        DataViewColumnImpl column = new DataViewColumnImpl("booking");
        column.setFilterProperties(new String[]{"booking.from", "booking.to"});
        column.setCellRenderer(renderer);
        column.setComparator(new BookingFromComparator());
        return column;
    }
}
